package org.go.smart.event;

import java.io.File;
import java.io.FileWriter;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
import java.util.Properties;
import java.util.logging.Logger;

//import javax.mail.Message;
//import javax.mail.MessagingException;
//import javax.mail.PasswordAuthentication;
//import javax.mail.Session;
//import javax.mail.Transport;
//import javax.mail.internet.InternetAddress;
//import javax.mail.internet.MimeMessage;

public class EventManager {
	
//	private String eventLogFileName = "";
//	private static String from = "gosmart.gabriel.opritoiu@gmail.com";
//	private static String to = "gabriel.opritoiu@gmail.com";
//	List<Event> events = new ArrayList<Event>();
//	
//	Logger logger = Logger.getLogger(EventManager.class.getName());
//	
//	public void addEvent(final Event event) {
//		this.events.add(event);
//		writeEventToFile(event);
//		processEvent(event);
//	}
//	
//	private void processEvent(Event event) {
//		if (event.getSeverity() == Event.Severity.critical) {
//			sendEmail(event);
//		}
//	}
//	
//	private void sendEmail(Event event) {
//		 Properties props = new Properties();
//         props.put("mail.smtp.host", "smtp.gmail.com");
//         props.put("mail.smtp.socketFactory.port", "465");
//         props.put("mail.smtp.socketFactory.class", "javax.net.ssl.SSLSocketFactory");
//         props.put("mail.smtp.auth", "true");
//         props.put("mail.smtp.port", "465");
//
//         Session session = Session.getDefaultInstance(props,
//             new javax.mail.Authenticator() {
//                 protected PasswordAuthentication getPasswordAuthentication() {
//                     return new PasswordAuthentication("gabriel.opritoiu@gmail.com","112358");
//                 }
//             });
//
//         try {
//
//             Message message = new MimeMessage(session);
//             message.setFrom(new InternetAddress(from));
//             message.setRecipients(Message.RecipientType.TO, InternetAddress.parse(to));
//             message.setSubject("Alert: " + event.getSeverity());
//             message.setContent("This is your product name : "+
//                     "Hi Krishna" +"<br></br>This is your price : "+ "Hi veni", "text/html; charset=utf-8");
//             Transport.send(message);
//
//             System.out.println("Done");
//
//         } catch (MessagingException e) {
//             throw new RuntimeException(e);
//         }
//        
//
//	}
//
//	public void writeEventToFile(final Event event) {
//		File eventLogFile = new File(eventLogFileName);
//		
//		FileWriter fileWriter = null;
//		try {
//			fileWriter = new FileWriter(eventLogFile);
//			fileWriter.append(event.toString() + "\n");
//		} catch (IOException e) {
//			e.printStackTrace();
//		} finally {
//			if (fileWriter != null) {
//				try {
//					fileWriter.close();
//				} catch (IOException e) {}
//			}
//		}
//	}
}
